home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / util / qtools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-18  |  12.0 KB  |  381 lines

  1. #define    LIBQTOOLS_CORE
  2. #include <libqtools.h>
  3.  
  4. /*
  5.  * global vars
  6.  */
  7.  
  8. int main(int argc, char **argv) {
  9.   int i;
  10.   char *outName = 0, *destDir = 0;
  11.   bool script = TRUE;
  12.   bool recurse = FALSE;
  13.   operation procOper = OP_DEFAULT;
  14.   unsigned char outType = TYPE_UNKNOWN;
  15.   unsigned char arcType = TYPE_UNKNOWN;
  16.  
  17. #if defined(DEBUG_C) && defined(HAVE_LIBDBMALLOC)
  18.   union dbmalloptarg m;
  19.  
  20.   m.i = M_HANDLE_IGNORE;
  21.   dbmallopt(MALLOC_FATAL, &m);
  22. #endif
  23.  
  24.   /* 
  25.    * definition of interaction:
  26.    *  if there is some to put out, use that specific type
  27.    *  else if there is some to get in, use the same specific type
  28.    */
  29.   for (i = 1; i < argc; i++) {
  30.     if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--palette")) {
  31.       argv[i] = 0;
  32.       palFile = __open(argv[++i], H_READ_BINARY);
  33.       argv[i] = 0;
  34.     }
  35.     else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--colormap")) {
  36.       argv[i] = 0;
  37.       colrFile = __open(argv[++i], H_READ_BINARY);
  38.       argv[i] = 0;
  39.     }
  40.     else if (!strcmp(argv[i], "-pp") || !strcmp(argv[i], "--preprocessor")) {
  41.       argv[i] = 0;
  42.       preProcessor = argv[++i];
  43.       argv[i] = 0;
  44.     }
  45.     else if (!strcmp(argv[i], "-dd") || !strcmp(argv[i], "--destdir")) {
  46.       argv[i] = 0;
  47.       destDir = argv[++i];
  48.       argv[i] = 0;
  49.     }
  50.     else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--darkness")) {
  51.       char *tmp;
  52.  
  53.       argv[i] = 0;
  54.       darkness = strtol(argv[++i], &tmp, 0);
  55.       argv[i] = 0;
  56.     }
  57.     else if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--output")) {
  58.       argv[i] = 0;
  59.       outName = argv[++i];
  60.       argv[i] = 0;
  61.     }
  62.     else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--recurse")) {
  63.       argv[i] = 0;
  64.       recurse = TRUE;
  65.     }
  66.     else if (!strcmp(argv[i], "-ppm") || !strcmp(argv[i], "--output-ppm")) {
  67.       argv[i] = 0;
  68.       outType = TYPE_PPM;
  69.     }
  70.     else if (!strcmp(argv[i], "-jpg") || !strcmp(argv[i], "--output-jpeg")) {
  71.       argv[i] = 0;
  72.       outType = TYPE_JPEG;
  73.     }
  74.     else if (!strcmp(argv[i], "-iff") || !strcmp(argv[i], "--output-ilbm")) {
  75.       argv[i] = 0;
  76.       outType = TYPE_ILBM;
  77.     }
  78.     else if (!strcmp(argv[i], "-png") || !strcmp(argv[i], "--output-png")) {
  79.       argv[i] = 0;
  80.       outType = TYPE_PNG;
  81.     }
  82.     else if (!strcmp(argv[i], "-vis") || !strcmp(argv[i], "--type-is-vis")) {
  83.       argv[i] = 0;
  84.       arcType = TYPE_VIS;
  85.     }
  86.     else if (!strcmp(argv[i], "-wv") || !strcmp(argv[i], "--bsp-watervis")) {
  87.       argv[i] = 0;
  88.       watervis = TRUE;
  89.     }
  90.     else if (!strcmp(argv[i], "-sv") || !strcmp(argv[i], "--bsp-slimevis")) {
  91.       argv[i] = 0;
  92.       slimevis = TRUE;
  93.     }
  94.     else if (!strcmp(argv[i], "-wl") || !strcmp(argv[i], "--light-waterlit")) {
  95.       argv[i] = 0;
  96.       waterlit = TRUE;
  97.     }
  98.     else if (!strcmp(argv[i], "-light") || !strcmp(argv[i], "--light")) {
  99.       argv[i] = 0;
  100.       newLit = TRUE;
  101.     }
  102.     else if (!strcmp(argv[i], "-pvs") || !strcmp(argv[i], "--pvs")) {
  103.       argv[i] = 0;
  104.       newVis = TRUE;
  105.     }
  106.     else if (!strcmp(argv[i], "-rad") || !strcmp(argv[i], "--light-rad")) {
  107.       argv[i] = 0;
  108.       doradiosity = TRUE;
  109.     }
  110.     else if (!strcmp(argv[i], "-nf") || !strcmp(argv[i], "--bsp-nofill")) {
  111.       argv[i] = 0;
  112.       nofill = TRUE;
  113.     }
  114.     else if (!strcmp(argv[i], "-nt") || !strcmp(argv[i], "--bsp-notjunc")) {
  115.       argv[i] = 0;
  116.       notjunc = TRUE;
  117.     }
  118.     else if (!strcmp(argv[i], "-nc") || !strcmp(argv[i], "--bsp-noclip")) {
  119.       argv[i] = 0;
  120.       noclip = TRUE;
  121.     }
  122.     else if (!strcmp(argv[i], "-oe") || !strcmp(argv[i], "--bsp-onlyentities")) {
  123.       argv[i] = 0;
  124.       onlyents = TRUE;
  125.     }
  126.     else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")) {
  127.       argv[i] = 0;
  128.       verbose = TRUE;
  129.     }
  130.     else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--fatal")) {
  131.       argv[i] = 0;
  132.       fatal = TRUE;
  133.     }
  134.     else if (!strcmp(argv[i], "-fv") || !strcmp(argv[i], "--vis-fastvis")) {
  135.       argv[i] = 0;
  136.       fastvis = TRUE;
  137.     }
  138.     else if (!strcmp(argv[i], "-uh") || !strcmp(argv[i], "--bsp-usehulls")) {
  139.       argv[i] = 0;
  140.       usehulls = TRUE;
  141.     }
  142.     else if (!strcmp(argv[i], "-ex") || !strcmp(argv[i], "--light-extra")) {
  143.       argv[i] = 0;
  144.       extra = TRUE;
  145.     }
  146.     else if (!strcmp(argv[i], "-sc") || !strcmp(argv[i], "--light-scale")) {
  147.       argv[i] = 0;
  148.       scale = atof(argv[++i]);
  149.       argv[i] = 0;
  150.     }
  151.     else if (!strcmp(argv[i], "-rn") || !strcmp(argv[i], "--light-range")) {
  152.       argv[i] = 0;
  153.       range = atof(argv[++i]);
  154.       argv[i] = 0;
  155.     }
  156.     else if (!strcmp(argv[i], "-vl") || !strcmp(argv[i], "--vis-level")) {
  157.       char *tmp;
  158.  
  159.       argv[i] = 0;
  160.       vislevel = strtol(argv[++i], &tmp, 0);
  161.       argv[i] = 0;
  162.     }
  163.     else if (!strcmp(argv[i], "-hn") || !strcmp(argv[i], "--bsp-hullnum")) {
  164.       char *tmp;
  165.  
  166.       argv[i] = 0;
  167.       hullnum = strtol(argv[++i], &tmp, 0);
  168.       argv[i] = 0;
  169.     }
  170.     else if (!strcmp(argv[i], "-sd") || !strcmp(argv[i], "--bsp-subdivide")) {
  171.       char *tmp;
  172.  
  173.       argv[i] = 0;
  174.       subdivide = strtol(argv[++i], &tmp, 0);
  175.       argv[i] = 0;
  176.     }
  177.     else if (!strcmp(argv[i], "-lit") || !strcmp(argv[i], "--type-is-light")) {
  178.       argv[i] = 0;
  179.       arcType = TYPE_LIT;
  180.     }
  181.     else if (!strcmp(argv[i], "-mip") || !strcmp(argv[i], "--type-is-mipmap")) {
  182.       argv[i] = 0;
  183.       arcType = TYPE_MIPMAP;
  184.     }
  185.     else if (!strcmp(argv[i], "-wal") || !strcmp(argv[i], "--type-is-wal")) {
  186.       argv[i] = 0;
  187.       arcType = outType = TYPE_WAL;
  188.     }
  189.     else if (!strcmp(argv[i], "-lmp") || !strcmp(argv[i], "--type-is-lump")) {
  190.       argv[i] = 0;
  191.       arcType = TYPE_LUMP;
  192.     }
  193.     else if (!strcmp(argv[i], "-ns") || !strcmp(argv[i], "--noscripting")) {
  194.       argv[i] = 0;
  195.       script = FALSE;
  196.     }
  197.     else if (!strcmp(argv[i], "-lz") || !strcmp(argv[i], "--compress")) {
  198.       argv[i] = 0;
  199.       Compression |= CMP_LZ77;
  200.     }
  201.     else if (!strcmp(argv[i], "-mip0") || !strcmp(argv[i], "--onlymip0")) {
  202.       argv[i] = 0;
  203.       Compression |= CMP_MIP0;
  204.     }
  205.     else if (!strcmp(argv[i], "-dt") || !strcmp(argv[i], "--dither")) {
  206.       char *tmp;
  207.  
  208.       argv[i] = 0;
  209.       dither = TRUE;
  210.       if((argv[i + 1][0] != '-') && (argv[i + 1][0] >= '0') && (argv[i + 1][0] <= '9')) {
  211.         dithervalue = strtol(argv[++i], &tmp, 0);
  212.         argv[i] = 0;
  213.         if (dithervalue < 16)
  214.       dithervalue = 16;
  215.         if (dithervalue > 256)
  216.       dithervalue = 256;
  217.       }
  218.     }
  219.     else if (!strcmp(argv[i], "-sm") || !strcmp(argv[i], "--smooth")) {
  220.       char *tmp;
  221.  
  222.       argv[i] = 0;
  223.       smoothing = TRUE;
  224.       if((argv[i + 1][0] != '-') && (argv[i + 1][0] >= '0') && (argv[i + 1][0] <= '9')) {
  225.         smoothingvalue = strtol(argv[++i], &tmp, 0);
  226.         argv[i] = 0;
  227.         if (smoothingvalue < 1)
  228.       smoothingvalue = 1;
  229.         if (smoothingvalue > 256)
  230.       smoothingvalue = 256;
  231.       }
  232.     }
  233.     else if (!strcmp(argv[i], "x")) {
  234.       argv[i] = 0;
  235.       procOper = OP_EXTRACT;
  236.     }
  237.     else if (!strcmp(argv[i], "d")) {
  238.       argv[i] = 0;
  239.       procOper = OP_DELETE;
  240.     }
  241.     else if (!strcmp(argv[i], "a")) {
  242.       argv[i] = 0;
  243.       procOper = OP_ADD;
  244.     }
  245.     else if (!strcmp(argv[i], "u")) {
  246.       argv[i] = 0;
  247.       procOper = OP_UPDATE;
  248.     }
  249.     else if (!strcmp(argv[i], "r")) {
  250.       argv[i] = 0;
  251.       procOper = OP_REPLACE;
  252.     }
  253.     else if (!strcmp(argv[i], "l")) {
  254.       argv[i] = 0;
  255.       procOper = OP_LIST;
  256.       /* disable every standard-activity for listing */
  257.       outType = 0;
  258.     }
  259.     else if (!strcmp(argv[i], "v")) {
  260.       argv[i] = 0;
  261.       procOper = OP_VIEW;
  262.       /* disable every standard-activity for viewing */
  263.       outType = 0;
  264.     }
  265.     else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
  266.       mprintf("%s [-<options>] [<command>] <file> ...
  267.  
  268.   options :
  269.  
  270.     -v, --verbose                     verbose output of informations
  271.     -f, --fatal                       make warnings errors
  272.     -ns, --noscripting                do not script all actions
  273.     -r, --recurse                     recurse operating
  274.  
  275.    input-basics:
  276.     -p, --palette <palette>           use this quake palette lump
  277.     -c, --colormap <colormap>         use this quake colormap lump
  278.     -pp, --preprocessor <commandline> filter quake-c through this preprocessor
  279.     -dd, --destdir <destdir>          alternative destination directory
  280.     -l, --darkness <darkness>         take this darkness
  281.     -lz, --compress                   compress wads
  282.     -mip0, --onlymip0                 store only miplevel 0 in wads
  283.     -dt, --dither [<value>]           dither floyd-steinberg with this error
  284.     -sm, --smooth [<value>]           smooth with this fraction
  285.     -light, --light              if bsp calculate light too
  286.     -pvs, --pvs                  if bsp calculate pvs (vis) too
  287.   
  288.    output-modifications:
  289.     -o, --output <file>               specify archive-content or output-name
  290.     -ppm, --output-ppm
  291.     -jpg, --output-jpeg
  292.     -iff, --output-ilbm
  293.     -png, --output-png                convert pictures and palettes to ppm/jpg/iff/png
  294.  
  295.    input-modifications
  296.     -vis, --type-is-vis               use inputfile(s) as vis-lump fors bsps
  297.     -lit, --type-is-light             use inputfile(s) as light-lump fors bsps
  298.     -mip, --type-is-mipmap            use inputfile(s) as raw-mipmap
  299.     -wal, --type-is-wal               use inputfile(s) as raw-wal
  300.     -lmp, --type-is-lump              use inputfile(s) as raw-lump
  301.  
  302.    options for bsp:
  303.     -wv, --bsp-watervis               make water visible in bsps
  304.     -sv, --bsp-slimevis               make slime visible in bsps
  305.     -nf, --bsp-nofill                 like -nofill in qbsp
  306.     -nt, --bsp-notjunc                like -notjunc in qbsp
  307.     -nc, --bsp-noclip                 like -noclip in qbsp
  308.     -oe, --bsp-onlyentities           like -onlyents in qbsp
  309.     -uh, --bsp-usehulls               like -usehulls in qbsp
  310.     -hn, --bsp-hullnum <hullnum>      like -hullnum in qbsp
  311.     -sd, --bsp-subdivide <subdivide>  like -subdivide in qbsp
  312.    
  313.    options for vis:
  314.     -vl, --vis-level <level>          how much vis-calculation
  315.     -fv, --vis-fastvis                like -fast in vis
  316.    
  317.    options for light:
  318.     -ex, --light-extra                like -extra in light
  319.     -rad, --light-rad                 do radiosity instead of old light algorithm
  320.     -wl, --light-waterlit             make water emit light
  321.     -sc, --light-range <range>        like -dist in light
  322.     -rn, --light-scale <scale>        like -scale in light
  323.    
  324.   commands:
  325.  
  326.    a                   add
  327.    d                   delete (unimplemented)
  328.    l                   list (default)
  329.    r                   replace (unimplemented)
  330.    u                   update (unimplemented)
  331.    v                   view (unimplemented)
  332.    x                   extract
  333.  
  334.   examples:
  335.  
  336.    %s test.bsp test.pak test.wad test.mdl test.spr
  337.     list all the contents of all the files
  338.    %s x test.bsp test.pak test.wad test.mdl test.spr
  339.     extract all the contents of all the files to the directory test.dir (bad :)
  340.    %s x test1.bsp test2.pak test3.wad test4.mdl test/test5.spr
  341.     extract all the contents of all the files to the directories test1.dir
  342.     test2.dir test3.dir test4.dir test/test5.dir (good ;)
  343.    %s -o *lava1 x test1.bsp
  344.     extract the raw-mipmap-texture *lava1 to test1.dir/*lava1.mip
  345.    %s -dd test -o *lava1 x test1.bsp
  346.     extract the raw-mipmap-texture *lava1 to test/test1.dir/*lava1.mip
  347.    %s -o *lava1 x test1.wad
  348.     extract the wad-content *lava1 to test1.dir/*lava1.<wad2-type>
  349.    %s -ppm -o *lava1 x test1.wad
  350.     extract the wad-content *lava1 to test1.dir/*lava1.ppm
  351.    %s -ppm -o *lava1.mip x test1.wad
  352.     extract the wad-content *lava1 to test1.dir/*lava1.mip with conversion to ppm
  353.     *lava1.mip is NOT a raw-mipmap-texture, its a PPM
  354.  
  355. (all rights reserved, Niels Froehling, Dyna-Tech 1998)
  356. ", argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]);
  357.       if (palFile)
  358.         __close(palFile);
  359.       if (colrFile)
  360.         __close(colrFile);
  361.       return 0;
  362.     }
  363.   }
  364.  
  365.   if(argc > 1) {
  366.     for (i = 1; i < argc; i++) {
  367.       if(argv[i]) {
  368.         processName(argv[i], destDir, outName, outType, 0, arcType, procOper, script, recurse);
  369.       }
  370.     }
  371.     if (palFile)
  372.       __close(palFile);
  373.     if (colrFile)
  374.       __close(colrFile);
  375.   }
  376.   else
  377.     mprintf("%s: no input files\nuse -h/--help for options\n", argv[0]);
  378.  
  379.   return 0;
  380. }
  381.